<h2 class="contentTitle">视频编辑</h2>


<div class="pageContent" layoutH="97">
	

			<dl>
				<dt>新分类名称：</dt>
				<dd>
					<input type="text" name="newname" id="newname"  value="<?php echo $contents->name;?>" class="required"  />
				</dd>
			</dl>
			<dl>
				<dt>讲师：</dt>
				<dd>
					<input type="text" name="tutor" id="tutor"  value="<?php echo $contents->tutor;?>" class="" alt="请输入讲师"/>
				</dd>
			</dl>
			<dl>
				<dt>价格：</dt>
				<dd>
					<input type="text" class="number textInput valid" id="price"  value="<?php echo $contents->price;?>"  name="price" alt="0.00"/>
				</dd>
			</dl>
			<dl>
				<dt>简介：</dt>
				<dd>
					<input type="text" id="summary" rows="2" class=""  value="<?php echo $contents->summary;?>"  name="summary"/>
				</dd>
			</dl>
            <dl>
				<dt>详细介绍：</dt>
				<dd>
                <textarea class="editor" id="introduction" name="introduction" rows="15" cols="100"><?php echo $contents->introduction;?></textarea>
				</dd>
			</dl>
    <ul>
				<li><div class="buttonActive"><div class="buttonContent"><button type="button" onclick="edit_data()">修改</button></div></div></li>
	  </ul>
    	<table class="table" width="100%" >
		<thead>
			<tr>
				<th width="80"></th>
				<th width="120">名称</th>
				<th width="240">简介</th>
				<th width="100">导师</th>
				<th width="80" align="center">观看</th>
			</tr>
		</thead>
		<tbody><?php $i=1; foreach($data as $id=>$value):?>
			<tr target="sid_user" rel="<?php echo $i++;?>">
                                <td></td>
				<td><?php echo $value->name;?></td>
				<td><?php echo $value->summary;?></td>
				<td><?php echo $value->tutor;?></td>
                                <td><a class="button" href="#" onclick="free_type('<?php echo $value->id;?>')" ><span id="free_type<?php echo $value->id;?>"><?php if($value->free == '0'):?>设为免费<?php else:?>设为收费<?php endif;?></span></a></td>
			</tr>
                        <?php endforeach;?>
		</tbody>
	</table>
</div>


<script type="text/javascript">
    function free_type(id)
    {
        var texts = $('#free_type'+id).html();
        if(texts != '设为免费')
        {
            var free_lenght = prompt("请输入免费的时长,单位为秒","");
            if(isNaN(free_lenght) || free_lenght < 1)
            {
                alert('免费时长必须是个数字,而且需要大于1');
                return false;
            }
        }
        else
        {
                var free_lenght = 0;
        }

        	$.ajax({ 
		type:'post',//可选get
                async:false,
		url:'<?php echo site_url('admin/video/edit_video_list_post');?>/'+id,//这里是接收数据的PHP程序   
		data:'free_lenght='+free_lenght,//传给PHP的数据，多个参数用&连接   
		dataType:'json',//服务器返回的数据类型 可选XML ,Json jsonp script html text等   
		success:function(data){
                                if(data.type)
                                {
                                        alert(data.msg);
                                        if(texts == '设为免费')
                                        {
                                            $('#free_type'+id).html('设为收费');
                                        }
                                        else
                                        {
                                            $('#free_type'+id).html('设为免费');
                                        }
                                }
                                else
                                {
                                        alert(data.msg);
                                }
                        },   
                        error:function(){   
                                alert('提交失败');
                        }   
                })
	return false;
    }
	
	
	
function edit_data()
    {
        var newname = $('#newname').val();
		var tutor = $('#tutor').val();
		var price = $('#price').val();
		var summary = $('#summary').val();
		var introduction = $('#introduction').val();
        
        $.ajax({ 
		type:'post',//可选get
        async:false,
		url:'<?php echo site_url('admin/video/edit_video_data_post/'.$tid);?>/',//这里是接收数据的PHP程序   
		data:'newname='+newname+'&tutor='+tutor+'&price='+price+'&summary='+summary+'&introduction='+introduction,//传给PHP的数据，多个参数用&连接   
		dataType:'json',//服务器返回的数据类型 可选XML ,Json jsonp script html text等   
		success:function(data){
                                if(data.statusCode == "200")
                                {
                                        alert(data.message);
                                }
                                else
                                {
                                        alert(data.message);
                                }
                        },   
                        error:function(){   
                                alert('提交失败');
                        }   
                })
	return false;
    }
</script>